package com.web.controller.web;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.web.dao.OrderMapper;
import com.web.domain.dataTable.BootstrapTableColumns;
import com.web.domain.dataTable.BootstrapTableResponse;
import com.web.entity.Order;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author FDjavaone
 * @date 2017/9/30
 */
@Slf4j
@Controller
public class WebOrderController {

    @Autowired
    private OrderMapper orderMapper;

    @RequestMapping(value = "syso",
            method = RequestMethod.GET)
    public String syso(Model model, HttpServletRequest request) {
        return "Order";
    }


    @Data
    public static class OrderColumns extends BootstrapTableColumns {
        private String orderNum;
        private String expressNumber;
        private String orderType;
        private Integer status;
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date begin_createTime;
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date begin_modifyTime;
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date end_createTime;
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private Date end_modifyTime;

    }


    @RequestMapping("/syso/getOrders")
    @ResponseBody
    public BootstrapTableResponse getOrders(OrderColumns orderColumns) {
        PageHelper.startPage(orderColumns.getPageNumber(), orderColumns.getPageSize());
        Page<Order> page = orderMapper.selectAllOrders(orderColumns);
        BootstrapTableResponse bootstrapTableResponse = new BootstrapTableResponse();
        bootstrapTableResponse.setResult(page.getResult());
        bootstrapTableResponse.setTotalCount(page.getTotal());
        return bootstrapTableResponse;
    }


}
